<?php echo $this->element('user'); ?>

<?php
	$javascript->link('question-logic', false);
?>

<script type="text/javascript">
	var myAnswers = new Array();
<?php

	foreach ($question['Answer'] as $answer){
		echo "var myAnswer".$answer['id']." = new Array();\n";
		echo "myAnswer".$answer['id']."['answer_text'] = '".$answer['answer_text']."';\n"; 		
		echo "myAnswer".$answer['id']."['answer_id'] = '".$answer['id']."';\n"; 	
		$correct = ($answer['correct'] == 1) ? 'true' : 'false';
		echo "myAnswer".$answer['id']."['answer_correct'] = ".$correct.";\n";
		echo "myAnswers.push(myAnswer".$answer['id'].");\n";
	}
	
?>
</script>

<?php echo $form->create('Question', array('action'=>'edit'));?>
<?php echo $form->hidden('id');?>

<fieldset>
<legend>Edit Question</legend>
<table>
	<tr><td><?php echo $form->input('name');?></td></tr>
	<tr><td><?php echo $form->input('Questiongroup', array('label'=>'Question Group'));?></td></tr>
	<tr><td><?php echo $form->input('answertype_id', array('label'=>'Type Of Answer'));?></td></tr>
	<tr><td><?php echo $form->input('question');?></td></tr>
	<tr><td><?php echo $form->input('random_answers', array('label'=>'Randomise Answers'));?></td></tr>
</table>
</fieldset>

<fieldset>
<legend>Answers</legend>
<div id="smalltext">
<a id="minus" alt="Remove Answer"><img src="/img/minus.gif" border="0" valign="center" ></a>&nbsp;
<a id="plus" alt="Add Answer"><img src="/img/plus.gif" border="0" valign="center"></a>
<?php 
	if ($question['Question']['answertype_id'] == 5){
		print '&nbsp;<a href="/questions/order/'.$question['Question']['id'].'" alt="Change Answer Order"><img src="/img/change_order.gif" border="0" valign="center"></a>';
	}
?>
</div>
<div id="output"></div>
<?php echo $form->end('Update Question'); ?>
</fieldset>
